package com.haixiaoke.business;

import com.haixiaoke.common.annotation.Log;
import com.haixiaoke.common.core.domain.AjaxResult;
import com.haixiaoke.common.core.page.TableDataInfo;
import com.haixiaoke.common.enums.BusinessType;
import com.haixiaoke.common.utils.poi.ExcelUtil;
import com.haixiaoke.domain.LockWarningLog;
import com.haixiaoke.service.ILockWarningLogService;
import com.haixiaoke.system.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 智能锁告警日志Controller
 *
 * @author qixi
 * @date 2023-05-27
 */
@RestController
@RequestMapping("/business/warningLog")
public class LockWarningLogController extends BaseController {
    @Autowired
    private ILockWarningLogService lockWarningLogService;

    /**
     * 查询智能锁告警日志列表
     */
    @PreAuthorize("@ss.hasPermi('business:log:list')")
    @GetMapping("/list")
    public TableDataInfo list(LockWarningLog lockWarningLog) {
        startPage();
        List<LockWarningLog> list = lockWarningLogService.selectLockWarningLogList(lockWarningLog);
        return getDataTable(list);
    }

    /**
     * 导出智能锁告警日志列表
     */
    @PreAuthorize("@ss.hasPermi('business:log:export')")
    @Log(title = "智能锁告警日志", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LockWarningLog lockWarningLog) {
        List<LockWarningLog> list = lockWarningLogService.selectLockWarningLogList(lockWarningLog);
        ExcelUtil<LockWarningLog> util = new ExcelUtil<>(LockWarningLog.class);
        util.exportExcel(response, list, "智能锁告警日志数据");
    }

    /**
     * 获取智能锁告警日志详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:log:query')")
    @GetMapping(value = "/{warningLogId}")
    public AjaxResult getInfo(@PathVariable("warningLogId") Long warningLogId) {
        return success(lockWarningLogService.selectLockWarningLogByWarningLogId(warningLogId));
    }


    /**
     * 新增智能锁告警日志
     */
    @PreAuthorize("@ss.hasPermi('business:log:add')")
    @Log(title = "智能锁告警日志", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LockWarningLog lockWarningLog) {
        return toAjax(lockWarningLogService.insertLockWarningLog(lockWarningLog));
    }

    /**
     * 修改智能锁告警日志
     */
    @PreAuthorize("@ss.hasPermi('business:log:edit')")
    @Log(title = "智能锁告警日志", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LockWarningLog lockWarningLog) {
        return toAjax(lockWarningLogService.updateLockWarningLog(lockWarningLog));
    }

    /**
     * 删除智能锁告警日志
     */
    @PreAuthorize("@ss.hasPermi('business:log:remove')")
    @Log(title = "智能锁告警日志", businessType = BusinessType.DELETE)
    @DeleteMapping("/{warningLogIds}")
    public AjaxResult remove(@PathVariable Long[] warningLogIds) {
        return toAjax(lockWarningLogService.deleteLockWarningLogByWarningLogIds(warningLogIds));
    }
}
